package com.xq.shop.controller.admin;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xq.shop.po.User;
import com.xq.shop.service.admin.IBaseService;
import com.xq.shop.service.admin.IUserService;
import com.xq.shop.util.AdminServiceFactory;
import com.xq.shop.vo.RespMsg;
import com.xq.shop.vo.SearchObject;
import com.xq.shop.vo.RespMsg.Result;

@Controller
@RequestMapping("/admin/")
public class UserController extends BaseController<User>{

	private IUserService userService = AdminServiceFactory.getUserService();
	
	@Override
	public IBaseService<User> getService() {
		return userService;
	}
	
	@RequestMapping("user_list.do")
	@ResponseBody
	public String list(SearchObject search){
		return super.list(search);
	}
	
	@RequestMapping("user_save.do")
	public ModelAndView save(User member, HttpServletResponse response){
		
		userService.saveOrUpdate(member);
		return new ModelAndView("admin/user/user_list").addObject(new RespMsg(Result.success, "保存成功"));
	}
	
	@RequestMapping("user_delete.do")
	public void delete(String id, HttpServletResponse response){
		
		super.delete(id, response);
	}
	
	@RequestMapping("user_edit.do")
	public ModelAndView edit(String id){
		
		return super.edit(id, new ModelAndView("admin/user/user_edit"));
	}
}
